<?php
// +----------------------------------------------------------------------
// | snake
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\api\controller;

use think\Controller;
use think\Db; 
use app\admin\model\UserModel;
session_start();
class Jrapi extends Controller
{

    //获取用户的openID
    public function getOpenId(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $js_code = $arr['js_code'];
            $url="https://api.weixin.qq.com/sns/jscode2session?appid=wx405ca5b18c8da118&secret=a6ead8efa94186d55e57ce7d87a2559a&js_code={$js_code}&grant_type=authorization_code";  
            $html = file_get_contents($url);  
            echo $html;

    } 
    //返回快速测试表内容
    public function fastTast(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $fast_test = db('fast_test'); 
        $arr = $fast_test->where("type = '{$arr['type']}' and multiple = '{$arr['multiple']}' and nature = '{$arr['job']}'") ->find();
      
         echo json_encode($arr);
    }

    // 首页轮播图
    public function bannerIndex(){
        $banner = db('ad')->where('type','1') -> select();
        echo json_encode($banner);
    }

    // 标的信息
    public function getTarget(){
        $target = db('goods_cat')->where('parent_id',3)->select();

       echo json_encode($target);

    }

    // 新闻信息
    public function getNews(){//改
        //$data = db('articles')->where('cat_id',2)->limit(3)->order('id desc')->select();
         $data = db('articles')->where("cat_id = 2 or cat_id = 3 or cat_id = 4 and id >62  ")->limit(3)->order('id desc')->select();
         $data = db('articles')->where("cat_id = 2 and id < 62  ")->limit(3)->order('id desc')->select();
         echo json_encode($data);
    }

    // 热销产品
    public function getProduct(){//改
           //$data = db('goods_cat')->where("parent_id = 1 and cat_id = 167")->select();
        $data = db('goods_cat')->where("parent_id = 1 ")->select();
        $goods = db("goods");
        $goods_cat;
        if($data !=null){

        
        foreach ($data as $key => $value) {
            $arr = $goods ->where("cat_id='{$value['cat_id']}' and  name like '%银行%' ") ->order('id desc')->limit(3) ->select();
            foreach ($arr as $k => $v) {
               $goods_cat[$value['cat_name']][$k] = $v;
            }
            
            }
        if(@$goods_cat != null){
         echo json_encode($goods_cat);
        }
    }
}
    // 快速测试 获得客户填写新
        // 数据包含 openId
    public function fastTastInfo(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);

        echo json_encode($arr);        
    }

    // 接收资产咨询表
    public function order(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $S = $arr;

        
        $order = db('order');
        $sn = date('Ymdhis') . str_pad(mt_rand(1, 9999), 4, '0', STR_PAD_LEFT);

        $d = date("Y-m-d H:i:s",time());
        //先插入订单的第一和第五页
        $a = isset($arr['plantSection'])?$arr['plantSection'][0]." ". $arr['plantSection'][1]." " .$arr['plantSection'][2]:'';
           
        $orderarr  = array(
            'order_sn' => $sn, 
            'time' => $d, 
           'openId' =>$arr['openId'],
            'userName' => $arr['userName'], 
            'mobile' => isset($arr['mobile'])?$arr['mobile']:'',
            'age' => isset($arr['age'])?$arr['age']:'',
            'sex' => isset($arr['sex'])?$arr['sex']:'',
            'degree' => isset($arr['degree'])?$arr['degree']:'',
            'isMarry' => isset($arr['isMarry'])?$arr['isMarry']:'',
            'userHousehold' => isset($arr['userHousehold'])?$arr['userHousehold'][0]." ". $arr['userHousehold'][1]." ". $arr['userHousehold'][2]:'',
            'job' => isset($arr['job'])?$arr['job']:'',
            'isLicense' =>  isset($arr['isLicense'])?$arr['isLicense']:'',
            'license' => isset($arr['license'])?$arr['license']:'',
            'operationScope' =>isset($arr['operationScope'])?$arr['operationScope']:'',
            'plantSection' => $a, 
            'plantSectionDetadil' => isset($arr['plantSectionDetadil'])?$arr['plantSectionDetadil']:'',
            'isWorkNumber' => isset($arr['isWorkNumber'])?$arr['isWorkNumber']:'',
            'bankFlow' => isset($arr['bankFlow'])?$arr['bankFlow']:'',
           
            'invoiceAmount' => isset($arr['invoiceAmount'])?$arr['invoiceAmount']:'',
            'isSecurity1' => isset($arr['isSecurity1'])?$arr['isSecurity1']:'',
            'security1' =>isset($arr['security1'])?$arr['security1']:'',
            'isPublicFunds1' => isset($arr['isPublicFunds1'])?$arr['isPublicFunds1']:'',
            'publickFunds1' => isset($arr['publickFunds1'])?$arr['publickFunds1']:'',
            'companyName' => isset($arr['companyName'])?$arr['companyName']:'', 
            'companyAdderess' => isset($arr['companyAdderess'])?$arr['companyAdderess'][0]." ". $arr['companyAdderess'][1]." " .$arr['companyAdderess'][2]:'', 
            'companyAdderessDetail' => isset($arr['companyAdderessDetail'])?$arr['companyAdderessDetail']:'',
            'Salary' => isset($arr['Salary'])?$arr['Salary']:'', 
            'bankFlow2' => isset($arr['bankFlow2'])?$arr['bankFlow2']:'',
            'isSecurity2' => isset($arr['isSecurity2'])?$arr['isSecurity2']:'',
            'security2' => isset($arr['security2'])?$arr['security2']:'',
            'isPublicFunds2' =>isset($arr['isPublicFunds2'])?$arr['isPublicFunds2']:'',
            'publickFunds2' => isset($arr['publickFunds2'])?$arr['publickFunds2']:'',
            //第五页
            'isCreditCard' => isset($arr['isCreditCard'])?$arr['isCreditCard']:'', 
            'CreditCardNumber' => isset($arr['CreditCardNumber'])?$arr['CreditCardNumber']:'',
            'CreditCardLimitMax' => isset($arr['CreditCardLimitMax'])?$arr['CreditCardLimitMax']:'',
            'CreditCardDate' => isset($arr['CreditCardDate'])?$arr['CreditCardDate']:'',
            'totalOweMoney' => isset($arr['totalOweMoney'])?$arr['totalOweMoney']:'',
            'isCreditCardNormal' => isset($arr['isCreditCardNormal'])?$arr['isCreditCardNormal']:'',
            'needToLoanMoney' => isset($arr['needToLoanMoney'])?$arr['needToLoanMoney']:'',
            'needToLoanTime' => isset($arr['needToLoanTime'])?$arr['needToLoanTime']:'',
            'Feedback' => isset($arr['Feedback'])?$arr['Feedback']:'',
            'wherePage' => isset($arr['wherePage'])?$arr['wherePage']:'',
             'pic' => isset($arr['pic'])?$arr['pic']:'',
             'salemanid' => isset($arr['SalesmanID'])?$arr['SalesmanID']:'',
              );
        
         $order ->insert($orderarr);
         $orderId =  $order->getLastInsID();

        
         //下面更新

         $arr['CompanyInsurances']='';
         $arr['InsuranceTypes']='';
         $arr['insuranceBuyTimes']='';
         $arr['InsurancePayTypes']='';
         $arr['PremiumAmounts']='';
         $arr['isPremiumPayfees']='';
         $arr['PremiumPayfees']='';

        //更新order表的其他页数据
        if($arr['isInsurance']){
           $arr['insuranceAmount'] = isset($arr['insuranceAmount'])?$arr['insuranceAmount']:0;
            for ($i=0; $i <=$arr['insuranceAmount'] ; $i++) { 
                if($i == 0){
                 $arr['CompanyInsurance'] = isset($arr['CompanyInsurance'])?$arr['CompanyInsurance']:'';   
                 $arr['CompanyInsurances'] = $arr['CompanyInsurance'] ;
                 $arr['InsuranceType'] = isset($arr['InsuranceType'])?$arr['InsuranceType']:'';   
                 $arr['InsuranceTypes'] = $arr['InsuranceType'] ;
                 $arr['insuranceBuyTime'] = isset($arr['insuranceBuyTime'])?$arr['insuranceBuyTime']:'';   
                 $arr['insuranceBuyTimes'] = $arr['insuranceBuyTime'] ;
                 $arr['InsurancePayType'] = isset($arr['InsurancePayType'])?$arr['InsurancePayType']:'';   
                 $arr['InsurancePayTypes'] = $arr['InsurancePayType'] ;
                 $arr['PremiumAmount'] = isset($arr['PremiumAmount'])?$arr['PremiumAmount']:'';   
                 $arr['PremiumAmounts'] = $arr['PremiumAmount'] ;
                 $arr['isPremiumPayfee'] = isset($arr['isPremiumPayfee'])?$arr['isPremiumPayfee']:'';   
                 $arr['isPremiumPayfees'] =$arr['isPremiumPayfee'] ;
                 $arr['PremiumPayfee'] = isset($arr['PremiumPayfee1'])?$arr['PremiumPayfee1']:'';   
                 $arr['PremiumPayfees'] =$arr['PremiumPayfee'] ;
            }else{
                 $arr['CompanyInsurances'] = $arr['CompanyInsurances'].",".$arr['CompanyInsurance'.($i+1)] ;
                 $arr['InsuranceTypes'] = $arr['InsuranceTypes'].",".$arr['InsuranceType'.($i+1)] ;
                 $arr['insuranceBuyTimes'] = $arr['insuranceBuyTimes'].",".$arr['insuranceBuyTime'.($i+1)] ;
                 $arr['InsurancePayTypes'] = $arr['InsurancePayTypes'].",".$arr['InsurancePayType'.($i+1)] ;
                 $arr['PremiumAmounts'] = $arr['PremiumAmounts'].",".$arr['PremiumAmount'.($i+1)] ;
                 $arr['isPremiumPayfees'] = $arr['isPremiumPayfees'].",".$arr['isPremiumPayfee'.($i+1)] ;
                 if($arr['isPremiumPayfee'.($i+1)] == 1){
                 $arr['PremiumPayfees'] = $arr['PremiumPayfees'].",".$arr['PremiumPayfee'.($i+1)] ;//参数有问题
             }else{
                $arr['PremiumPayfees'] = $arr['PremiumPayfees'].",".'' ;
             }
            }
        } 
    }
                 $arr['carBrands'] = '';
                 $arr['CarBillPrices'] = '';
                 $arr['CarYearss'] = '';
                 $arr['BuyCarTypes'] = '';
                 $arr['CarFirstPays'] ='';
                 $arr['CarMonthPays'] = '';
                 $arr['CarPayTimess'] = '';
                 $arr['isCarSupplys'] = '';
                 $arr['CarSupplyTimes'] = '';
                 $arr['carWhichBanks'] = '';
                 $arr['isCarInsurances'] = '';
                 $arr['carInsuranceCompanys'] = '';
                 $arr['CarInsuranceCosts'] = '';
        //更新order表的其他页数据
        if($arr['isCar']){
           $arr['carsAmount'] = isset($arr['carsAmount'])?$arr['carsAmount']:0;
            for ($i=0; $i <=$arr['carsAmount'] ; $i++) { 
                if($i == 0){
                 $arr['carBrand'] = isset($arr['carBrand'])?$arr['carBrand']:'';   
                 $arr['carBrands'] = $arr['carBrand'] ;
                 $arr['CarBillPrice'] = isset($arr['CarBillPrice'])?$arr['CarBillPrice']:'';   
                 $arr['CarBillPrices'] = $arr['CarBillPrice'] ;
                 $arr['CarYears'] = isset($arr['CarYears'])?$arr['CarYears']:'';   
                 $arr['CarYearss'] = $arr['CarYears'] ;
                 $arr['BuyCarType'] = isset($arr['BuyCarType'])?$arr['BuyCarType']:'';   
                 $arr['BuyCarTypes'] = $arr['BuyCarType'] ;
                 $arr['CarFirstPay'] = isset($arr['CarFirstPay'])?$arr['CarFirstPay']:'';   
                 $arr['CarFirstPays'] = $arr['CarFirstPay'] ;
                 $arr['CarMonthPay'] = isset($arr['CarMonthPay'])?$arr['CarMonthPay']:'';   
                 $arr['CarMonthPays'] =$arr['CarMonthPay'] ;
                 $arr['CarPayTimes'] = isset($arr['CarPayTimes'])?$arr['CarPayTimes']:'';   
                 $arr['CarPayTimess'] =$arr['CarPayTimes'] ; 
                 $arr['isCarSupply'] = isset($arr['isCarSupply'])?$arr['isCarSupply']:'';   
                 $arr['isCarSupplys'] =$arr['isCarSupply'] ;
                 $arr['CarSupplyTime'] = isset($arr['CarSupplyTime'])?$arr['CarSupplyTime']:'';   
                 $arr['CarSupplyTimes'] =$arr['CarSupplyTime'] ;
                 $arr['carWhichBank'] = isset($arr['carWhichBank'])?$arr['carWhichBank']:'';   
                 $arr['carWhichBanks'] =$arr['carWhichBank'] ;
                 $arr['isCarInsurance'] = isset($arr['isCarInsurance'])?$arr['isCarInsurance']:'';   
                 $arr['isCarInsurances'] =$arr['isCarInsurance'] ;
                 $arr['carInsuranceCompany'] = isset($arr['carInsuranceCompany'])?$arr['carInsuranceCompany']:'';   
                 $arr['carInsuranceCompanys'] =$arr['carInsuranceCompany'] ;
                 $arr['CarInsuranceCost'] = isset($arr['CarInsuranceCost'])?$arr['CarInsuranceCost']:'';   
                 $arr['CarInsuranceCosts'] =$arr['CarInsuranceCost'] ;


            }else{
               

                 $arr['carBrands'] = $arr['carBrands'].",".$arr['carBrand'.($i+1)] ;
                 $arr['CarBillPrices'] = $arr['CarBillPrices'].",".$arr['CarBillPrice'.($i+1)] ;
                 $arr['CarYearss'] = $arr['CarYearss'].",".$arr['CarYears'.($i+1)] ;
                 $arr['BuyCarTypes'] = $arr['BuyCarTypes'].",".$arr['BuyCarType'.($i+1)] ;
            

                 if($arr['BuyCarType'.($i+1)] == 2){
                 $arr['CarFirstPays'] = $arr['CarFirstPays'].",".$arr['CarFirstPay'.($i+1)] ;
                 $arr['CarMonthPays'] = $arr['CarMonthPays'].",".$arr['CarMonthPay'.($i+1)] ;
                 $arr['CarPayTimess'] = $arr['CarPayTimess'].",".$arr['CarPayTimes'.($i+1)] ;
                 $arr['isCarSupplys'] = $arr['isCarSupplys'].",".$arr['isCarSupply'.($i+1)] ;
                 if($arr['isCarSupply'.($i+1)] ==1){
                 $arr['CarSupplyTimes'] = $arr['CarSupplyTimes'].",".$arr['CarSupplyTime'.($i+1)] ;}//参输错误
                 $arr['carWhichBanks'] = $arr['carWhichBanks'].",".$arr['carWhichBank'.($i+1)] ;
                 $arr['isCarInsurances'] = $arr['isCarInsurances'].",".$arr['isCarInsurance'.($i+1)] ;
                 if($arr['isCarInsurance'.($i+1)] == 1){
                 $arr['carInsuranceCompanys'] = $arr['carInsuranceCompanys'].",".$arr['carInsuranceCompany'.($i+1)] ;
                 $arr['CarInsuranceCosts'] = $arr['CarInsuranceCosts'].",".$arr['CarInsuranceCost'.($i+1)] ;}
             }else{
                 $arr['CarFirstPays'] = $arr['CarFirstPays'].",".'' ;
                 $arr['CarMonthPays'] = $arr['CarMonthPays'].",".'' ;
                 $arr['CarPayTimess'] = $arr['CarPayTimess'].",".'' ;
                 $arr['isCarSupplys'] = $arr['isCarSupplys'].",".'' ;
                 
                 $arr['CarSupplyTimes'] = $arr['CarSupplyTimes'].",".'' ;//参输错误
                 $arr['carWhichBanks'] = $arr['carWhichBanks'].",".'' ;
                 $arr['isCarInsurances'] = $arr['isCarInsurances'].",".'' ;
                
                 $arr['carInsuranceCompanys'] = $arr['carInsuranceCompanys'].",".'' ;
                 $arr['CarInsuranceCosts'] = $arr['CarInsuranceCosts'].",".'' ;}
             
           

            }
        } 
    }
                $arr['houseTypes'] = '';
                 $arr['houseAddresss'] = '';
                 $arr['houseSizes'] = '';
                 $arr['houseCosts'] = '';
                 $arr['houseByTypes'] = '';
                 $arr['houseDegrees'] = '';
                 $arr['houseFirstPays'] = '';
                 $arr['HouseMonthPays'] ='';
                 $arr['HousePayTimess'] = '';
                 $arr['HouseWhichBanks'] = '';
                 $arr['HouseLoanWhos'] = '';
                 $arr['isHouseSupplys'] = '';
                 $arr['HouseSupplyTimes'] ='';
                 $arr['houseContracts'] = '';
                 $arr['houseBelongs'] = '';
             //更新order表的其他页数据第三页
        if($arr['isHouse']){
           $arr['HouseAmount'] = isset($arr['HouseAmount'])?$arr['HouseAmount']:0;
            for ($i=0; $i <=$arr['HouseAmount'] ; $i++) { 
                if($i == 0){
                 $arr['houseType'] = isset($arr['houseType'])?$arr['houseType']:'';   
                 $arr['houseTypes'] = $arr['houseType'] ;
                 $arr['houseAddress'] = isset($arr['houseAddress'])?$arr['houseAddress']:'';   
                 $arr['houseAddresss'] = $arr['houseAddress'] ;
                 $arr['houseSize'] = isset($arr['houseSize'])?$arr['houseSize']:'';   
                 $arr['houseSizes'] = $arr['houseSize'] ;
                 $arr['houseCost'] = isset($arr['houseCost'])?$arr['houseCost']:'';   
                 $arr['houseCosts'] = $arr['houseCost'] ;
                 $arr['houseByType'] = isset($arr['houseByType'])?$arr['houseByType']:'';   
                 $arr['houseByTypes'] = $arr['houseByType'] ;
                 $arr['houseDegree'] = isset($arr['houseDegree'])?$arr['houseDegree']:'';   
                 $arr['houseDegrees'] =$arr['houseDegree'] ;
                 $arr['houseFirstPay'] = isset($arr['houseFirstPay'])?$arr['houseFirstPay']:'';   
                 $arr['houseFirstPays'] =$arr['houseFirstPay'] ; 
                 $arr['HouseMonthPay'] = isset($arr['HouseMonthPay'])?$arr['HouseMonthPay']:'';   
                 $arr['HouseMonthPays'] =$arr['HouseMonthPay'] ;
                 $arr['HousePayTimes'] = isset($arr['HousePayTimes'])?$arr['HousePayTimes']:'';   
                 $arr['HousePayTimess'] =$arr['HousePayTimes'] ;
                 $arr['HouseWhichBank'] = isset($arr['HouseWhichBank'])?$arr['HouseWhichBank']:'';   
                 $arr['HouseWhichBanks'] =$arr['HouseWhichBank'] ;
                 $arr['HouseLoanWho'] = isset($arr['HouseLoanWho'])?$arr['HouseLoanWho']:'';   
                 $arr['HouseLoanWhos'] =$arr['HouseLoanWho'] ;
                 $arr['isHouseSupply'] = isset($arr['isHouseSupply'])?$arr['isHouseSupply']:'';   
                 $arr['isHouseSupplys'] =$arr['isHouseSupply'] ;
                 $arr['HouseSupplyTime'] = isset($arr['HouseSupplyTime'])?$arr['HouseSupplyTime']:'';   
                 $arr['HouseSupplyTimes'] =$arr['HouseSupplyTime'] ;
                 $arr['houseContract'] = isset($arr['houseContract'])?$arr['houseContract']:'';   
                 $arr['houseContracts'] =$arr['houseContract'] ;
                 $arr['houseBelong'] = isset($arr['houseBelong'])?$arr['houseBelong']:'';   
                 $arr['houseBelongs'] =$arr['houseBelong'] ;


            }else{
               

                 $arr['houseTypes'] = $arr['houseTypes'].",".$arr['houseType'.($i+1)] ;
                 $arr['houseAddresss'] = $arr['houseAddresss'].",".$arr['houseAddress'.($i+1)] ;
                 $arr['houseSizes'] = $arr['houseSizes'].",".$arr['houseSize'.($i+1)] ;
                 $arr['houseCosts'] = $arr['houseCosts'].",".$arr['houseCost'.($i+1)] ;
                 $arr['houseByTypes'] = $arr['houseByTypes'].",".$arr['houseByType'.($i+1)] ;
            if(  $arr['houseByType'.($i+1)] == 1){ $arr['houseDegrees'] = $arr['houseDegrees'].",".$arr['houseDegree'.($i+1)] ;} //数据对不上
                 
            if($arr['houseByType'.($i+1)] == 2){
                 $arr['houseFirstPays'] = $arr['houseFirstPays'].",".$arr['houseFirstPay'.($i+1)] ;
                 $arr['HouseMonthPays'] = $arr['HouseMonthPays'].",".$arr['HouseMonthPay'.($i+1)] ;
                 $arr['HousePayTimess'] = $arr['HousePayTimess'].",".$arr['HousePayTimes'.($i+1)] ;
                 $arr['HouseWhichBanks'] = $arr['HouseWhichBanks'].",".$arr['HouseWhichBank'.($i+1)] ;
                 $arr['HouseLoanWhos'] = $arr['HouseLoanWhos'].",".$arr['HouseLoanWho'.($i+1)] ;
                 $arr['isHouseSupplys'] = $arr['isHouseSupplys'].",".$arr['isHouseSupply'.($i+1)] ;
                 if($arr['isHouseSupply'.($i+1)] == 1){
                    $arr['HouseSupplyTimes'] = $arr['HouseSupplyTimes'].",".$arr['HouseSupplyTime'.($i+1)] ;//数据对不上
                 }else{
                     $arr['HouseSupplyTimes'] = $arr['HouseSupplyTimes'].",".'' ;
                 }
                 
                 
                 $arr['houseContracts'] = $arr['houseContracts'].",".$arr['houseContract'.($i+1)] ;
                 $arr['houseBelongs'] = $arr['houseBelongs'].",".$arr['houseBelong'.($i+1)] ;
}else{
                 $arr['houseFirstPays'] = $arr['houseFirstPays'].",".'' ;
                 $arr['HouseMonthPays'] = $arr['HouseMonthPays'].",".'' ;
                 $arr['HousePayTimess'] = $arr['HousePayTimess'].",".'' ;
                 $arr['HouseWhichBanks'] = $arr['HouseWhichBanks'].",".'' ;
                 $arr['HouseLoanWhos'] = $arr['HouseLoanWhos'].",".'' ;
                 $arr['isHouseSupplys'] = $arr['isHouseSupplys'].",".'' ;
               
                $arr['HouseSupplyTimes'] = $arr['HouseSupplyTimes'].",".'' ;//数据对不上
                
                 
                 
                 $arr['houseContracts'] = $arr['houseContracts'].",".'' ;
                 $arr['houseBelongs'] = $arr['houseBelongs'].",".'' ;
}        
            }
        } 
    }   
                $arr['HandleLoanss'] = '';
                 $arr['LoanMethods'] = '';
                 $arr['LoanWheres'] = '';
                 $arr['LoansCosts'] = '';
                 $arr['LoansDates'] = '';
                 $arr['LoansRepayMonths'] = '';
                 $arr['isLoanOnTimes'] = '';
                //更新order表的其他页数据 第四页
        if($arr['isRepayLoan']){
           $arr['loanAmount'] = isset($arr['loanAmount'])?$arr['loanAmount']:0;
            for ($i=0; $i <=$arr['loanAmount'] ; $i++) { 
                if($i == 0){
                 $arr['HandleLoans'] = isset($arr['HandleLoans'])?$arr['HandleLoans']:'';   
                 $arr['HandleLoanss'] = $arr['HandleLoans'] ;
                 $arr['LoanMethod'] = isset($arr['LoanMethod'])?$arr['LoanMethod']:'';   
                 $arr['LoanMethods'] = $arr['LoanMethod'] ;
                 $arr['LoanWhere'] = isset($arr['LoanWhere'])?$arr['LoanWhere']:'';   
                 $arr['LoanWheres'] = $arr['LoanWhere'] ;
                 $arr['LoansCost'] = isset($arr['LoansCost'])?$arr['LoansCost']:'';   
                 $arr['LoansCosts'] = $arr['LoansCost'] ;
                 $arr['LoansDate'] = isset($arr['LoansDate'])?$arr['LoansDate']:'';   
                 $arr['LoansDates'] = $arr['LoansDate'] ;
                 $arr['LoansRepayMonth'] = isset($arr['LoansRepayMonth'])?$arr['LoansRepayMonth']:'';   
                 $arr['LoansRepayMonths'] =$arr['LoansRepayMonth'] ;
                 $arr['isLoanOnTime'] = isset($arr['isLoanOnTime'])?$arr['isLoanOnTime']:'';   
                 $arr['isLoanOnTimes'] =$arr['isLoanOnTime'] ;
            }else{
                 $arr['HandleLoanss'] = $arr['HandleLoanss'].",".$arr['HandleLoans'.($i+1)] ;
                 $arr['LoanMethods'] = $arr['LoanMethods'].",".$arr['LoanMethod'.($i+1)] ;
                 $arr['LoanWheres'] = $arr['LoanWheres'].",".$arr['LoanWhere'.($i+1)] ;
                 $arr['LoansCosts'] = $arr['LoansCosts'].",".$arr['LoansCost'.($i+1)] ;
                 $arr['LoansDates'] = $arr['LoansDates'].",".$arr['LoansDate'.($i+1)] ;
                 $arr['LoansRepayMonths'] = $arr['LoansRepayMonths'].",".$arr['LoansRepayMonth'.($i+1)] ;
                 $arr['isLoanOnTimes'] = $arr['isLoanOnTimes'].",".$arr['isLoanOnTime'.($i+1)] ;
            }
        } 
    }   
                 $arr['WhereCheckCreditMonths'] = '';
                 
                 $arr['WhereCheckCreditYearss'] = ''; 
                
         if($arr['isCheckCredit']){
           $arr['CheckCreditMonth'] = isset($arr['CheckCreditMonth'])?$arr['CheckCreditMonth']:0;
            for ($i=0; $i <=$arr['CheckCreditMonth'] ; $i++) { 
                if($i == 0){
                 $arr['WhereCheckCreditMonth'] = isset($arr['WhereCheckCreditMonth'])?$arr['WhereCheckCreditMonth']:'';   
                 $arr['WhereCheckCreditMonths'] = $arr['WhereCheckCreditMonth'] ;
                 
                 
            }else{
                 $arr['WhereCheckCreditMonths'] = $arr['WhereCheckCreditMonths'].",".$arr['WhereCheckCreditMonth'.($i+1)] ;
               
                
            }
        } 
    }
            //var_dump($arr['CheckCreditMonth']);var_dump("aaaaa"); var_dump($arr['WhereCheckCreditMonths']);
            if($arr['isCheckCredit']){
           $arr['CheckCreditYears'] = isset($arr['CheckCreditYears'])?$arr['CheckCreditYears']:0;
            for ($i=0; $i <=$arr['CheckCreditYears'] ; $i++) { 
                if($i == 0){
                 $arr['WhereCheckCreditYears'] = isset($arr['WhereCheckCreditYears'])?$arr['WhereCheckCreditYears']:'';   
                 $arr['WhereCheckCreditYearss'] = $arr['WhereCheckCreditYears'] ;
                 
            }else{
                 
                 $arr['WhereCheckCreditYearss'] = $arr['WhereCheckCreditYearss'].",".$arr['WhereCheckCreditYears'.($i+1)] ;
                
            }
        } 
    }

            //更新剩下的资料
            $orderupdate = array(
                'isInsurance' => isset($arr['isInsurance'])?$arr['isInsurance']:'',
                'insuranceAmount' => isset($arr['insuranceAmount'])?$arr['insuranceAmount']:'',
                'CompanyInsurance' => isset($arr['CompanyInsurances'])?$arr['CompanyInsurances']:'',
                'InsuranceType' => isset($arr['InsuranceTypes'])?$arr['InsuranceTypes']:'',
                'insuranceBuyTime' => isset($arr['insuranceBuyTimes'])?$arr['insuranceBuyTimes']:'',
                'InsurancePayType' => isset($arr['InsurancePayTypes'])?$arr['InsurancePayTypes']:'',
                'PremiumAmount' => isset($arr['PremiumAmounts'])?$arr['PremiumAmounts']:'',
                'isPremiumPayfee' => isset($arr['isPremiumPayfees'])?$arr['isPremiumPayfees']:'',
                'PremiumPayfee' => isset($arr['PremiumPayfees'])?$arr['PremiumPayfees']:'',

                'isCar' => isset($arr['isCar'])?$arr['isCar']:'', 
                'carsAmount' => isset($arr['carsAmount'])?$arr['carsAmount']:'',
                'carBrand' => isset($arr['carBrands'])?$arr['carBrands']:'',
                'CarBillPrice' => isset($arr['CarBillPrices'])?$arr['CarBillPrices']:'',
                'CarYears' => isset($arr['CarYearss'])?$arr['CarYearss']:'',
                'BuyCarType' => isset($arr['BuyCarTypes'])?$arr['BuyCarTypes']:'',
                'CarFirstPay' => isset($arr['CarFirstPays'])?$arr['CarFirstPays']:'',
                'CarMonthPay' =>isset($arr['CarMonthPays'])?$arr['CarMonthPays']:'',
                'CarPayTimes' => isset($arr['CarPayTimess'])?$arr['CarPayTimess']:'',
                'isCarSupply' => isset($arr['isCarSupplys'])?$arr['isCarSupplys']:'',
                'CarSupplyTime' => isset($arr['CarSupplyTimes'])?$arr['CarSupplyTimes']:'',
                'carWhichBank' => isset($arr['carWhichBanks'])?$arr['carWhichBanks']:'',
                'isCarInsurance' => isset($arr['isCarInsurances'])?$arr['isCarInsurances']:'',
                'carInsuranceCompany' => isset($arr['carInsuranceCompanys'])?$arr['carInsuranceCompanys']:'',
                'CarInsuranceCost' => isset($arr['CarInsuranceCosts'])?$arr['CarInsuranceCosts']:'',


                 'isHouse' => isset($arr['isHouse'])?$arr['isHouse']:'',
                'HouseAmount' => isset($arr['HouseAmount'])?$arr['HouseAmount']:'',
                'houseType' => isset($arr['houseTypes'])?$arr['houseTypes']:'',
                'houseAddress' => isset($arr['houseAddresss'])?$arr['houseAddresss']:'',
                'houseSize' => isset($arr['houseSizes'])?$arr['houseSizes']:'',
                'houseCost' => isset($arr['houseCosts'])?$arr['houseCosts']:'',
                'houseByType' => isset($arr['houseByTypes'])?$arr['houseByTypes']:'',
                'houseFirstPay' => isset($arr['houseFirstPays'])?$arr['houseFirstPays']:'',
                'HouseMonthPay' => isset($arr['HouseMonthPays'])?$arr['HouseMonthPays']:'',
                'HousePayTimes' => isset($arr['HousePayTimess'])?$arr['HousePayTimess']:'',
                'HouseWhichBank' => isset($arr['HouseWhichBanks'])?$arr['HouseWhichBanks']:'',
                'HouseLoanWho' => isset($arr['HouseLoanWhos'])?$arr['HouseLoanWhos']:'',
                'isHouseSupply' => isset($arr['isHouseSupplys'])?$arr['isHouseSupplys']:'',
                'HouseSupplyTime' => isset($arr['HouseSupplyTimes'])?$arr['HouseSupplyTimes']:'',
                'houseContract' => isset($arr['houseContracts'])?$arr['houseContracts']:'',
                'houseBelong' => isset($arr['houseBelongs'])?$arr['houseBelongs']:'',
                'houseDegree' => isset($arr['houseDegrees'])?$arr['houseDegrees']:'',
                    //第四页
                 'isRepayLoan' => isset($arr['isRepayLoan'])?$arr['isRepayLoan']:'', 
                'loanAmount' => isset($arr['loanAmount'])?$arr['loanAmount']:'',
                'HandleLoans' => isset($arr['HandleLoanss'])?$arr['HandleLoanss']:'',
                'LoanMethod' => isset($arr['LoanMethods'])?$arr['LoanMethods']:'',
                'LoanWhere' => isset($arr['LoanWheres'])?$arr['LoanWheres']:'',
                'LoansCost' => isset($arr['LoansCosts'])?$arr['LoansCosts']:'',
                'LoansDate' => isset($arr['LoansDates'])?$arr['LoansDates']:'',
                'LoansRepayMonth' => isset($arr['LoansRepayMonths'])?$arr['LoansRepayMonths']:'',
                'isLoanOnTime' => isset($arr['isLoanOnTimes'])?$arr['isLoanOnTimes']:'',
                

                'isCheckCredit' => isset($arr['isCheckCredit'])?$arr['isCheckCredit']:'', 
                'CheckCreditMonth' => isset($arr['CheckCreditMonth'])?$arr['CheckCreditMonth']:'', 
                'WhereCheckCreditMonth' => isset($arr['WhereCheckCreditMonths'])?$arr['WhereCheckCreditMonths']:'', 
                'WhereCheckCreditYears' => isset($arr['WhereCheckCreditYearss'])?$arr['WhereCheckCreditYearss']:'', 
                'CheckCreditYears' =>isset($arr['CheckCreditYears'])?$arr['CheckCreditYears']:'',

               );
       
        $id = $order ->where("id = $orderId ")-> update($orderupdate);
         
            echo 1;
           $list = $order ->where("id = $orderId ")-> find();
           $mobile = $list['mobile'];
            $code = mt_rand(1000, 9999);
           $result = sendMsg3($mobile,$code);// 通知反馈
           $salemanid = $list['salemanid'];
           if($salemanid != null){
           $lists = db('user') ->where('id', $salemanid)-> find();

           $code =  $list['userName'];
            $mobile = $lists['phone'];
           
             $result = sendMsg2($mobile, $code);//业务通知
           
         }
           // //后台管理员通知
           //  $code =  "";
           //  $mobile = 18029339183;
           //  $result = sendMsg4($mobile, $code);
           //  $mobile = 13925435420;
           //  $result = sendMsg4($mobile, $code);
}
    // 商品大纲 分类
    public function getClassify(){//改
       // $data = db('goods_cat')->where('parent_id',1)->select();
        $data = db('goods_cat')->where("parent_id = 1 and cat_id > 160")->select();
        $data = db('goods_cat')->where("parent_id = 1 ")->select();
        
        $result = array();
         foreach ($data as $key => $value) { 
            $arr = db('goods') ->where('cat_id',$value['cat_id'])->select();
        $arr = db('goods') ->where("cat_id='{$value['cat_id']}' and name like '%银行%' ")->select();
            foreach ($arr as $k => $v) {
                array_push($result,$v["id"]);
            }
            $data[$key]["goods"] = $result;
            $data[$key]["id"] = 'a'.$value["cat_id"];
            $result = array();

         }

       echo json_encode($data);
    }

    // 商品大纲 商品
    public function productMixGoods(){//改
      $data = db('goods')->where('goods_type',1)->select();
        // $data = db('goods')->where("goods_type = 3 and cat_id > 160")->select();
        $result;
        foreach ($data as $key => $value) {
            $result[$value["id"]] = $value;
        }

        echo json_encode($result);
    }

    // 标的商品 分类
    public function getMatterClassify(){//改
        //$data = db('goods_cat')->where('parent_id',3)->select();
         $data = db('goods_cat')->where("parent_id = 1 and cat_id > 160")->select();
           $data = db('goods_cat')->where("parent_id = 1 ")->select();
        $result = array();
         foreach ($data as $key => $value) {
            $arr = db('goods') ->where('cat_id',$value['cat_id'])->select();
 $arr = db('goods') ->where("cat_id='{$value['cat_id']}' and name like '%银行%' ")->select();
            foreach ($arr as $k => $v) {
                array_push($result,$v["id"]);
            }
            $data[$key]["goods"] = $result;
            $data[$key]["id"] = 'a'.$value["cat_id"];
            $result = array();

         }
         // var_dump($data);die();

         echo json_encode($data);
    }

    // 标的 商品
    public function matterGoods(){//改
      // $data = db('goods')->where('goods_type',4)->select();
          $data = db('goods')->where("goods_type = 3 and cat_id > 160")->select();
           $data = db('goods')->where('goods_type',1)->select();
        $result;
        foreach ($data as $key => $value) {
            $result[$value["id"]] = $value;
        }

       echo json_encode($result);
    }

    // 新闻列表
        // 新闻加载更多
        // 分页参考网站 https://blog.csdn.net/h330531987/article/details/78319595
    public function newsList(){//改
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        switch ($arr["type"]) {
            // 0 企业新闻
            case '0':
                // 分页测试数据 , 每次传一条数据,以后再修改
                $data = db('articles')->where("cat_id = 2 and id <61 ")->order('id desc')->paginate(10,true,[
                    'page' => $arr["page"],
                ]);//'cat_id',2
               echo json_encode($data);
                break;
            // 1 行业新闻
            case '1':
                // 分页测试数据 , 每次传一条数据,以后再修改
                $data = db('articles')->where("cat_id = 3  and id <61 ")->order('id desc')->paginate(10,true,[
                    'page' => $arr["page"],
                ]);
               echo json_encode($data);
                break;
            // 2 金融咨询 
            case '2':
            // 分页测试数据 , 每次传一条数据,以后再修改
                $data = db('articles')->where("cat_id = 4  and id <61 ")->order('id desc')->paginate(10,true,[
                    'page' => $arr["page"],
                ]);
                 echo json_encode($data);
            break;
            
        }
    }

    // 猜你喜欢 , 随机抽取数据库信息
    public function guessLike(){
        // 查询数据库
        $data = Db::query("SELECT * FROM `snake_goods` WHERE id >= (SELECT floor( RAND() * ((SELECT MAX(id) FROM `snake_goods`)-(SELECT MIN(id) FROM `snake_goods`)) + (SELECT MIN(id) FROM `snake_goods`))) and goods_type != 2  and (id = 498  or id = 496) ORDER BY id LIMIT 3");
        $data = Db::query("SELECT * FROM `snake_goods` WHERE id = 498  or id = 496 ");
       
        if($data != null){
        $result;

        foreach ($data as $key => $value) {
            $result[$value["id"]] = $value;
        }

      echo json_encode($result);
    }

    }
    // 商品加载更多
    public function moreGoods(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $cat_id = $arr['cat_id'];
        $page = $arr['page'];

        $data = db('goods')->where("cat_id='{$cat_id}' and goods_type = 3")->paginate(10,true,[
            'page' => $page,
        ]);

  echo json_encode($data);
    }
     // 商品加载更多
    public function moreGoods2(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $cat_id = $arr['cat_id'];
        $page = $arr['page'];
        if(@$arr['money'] == 1){
            
             $data = db('goods')->where("cat_id='{$cat_id}' and name like '%银行%'  ")->paginate(1000,true,[
                    'page' => $page,
                ]);
           
            
        }else{
           
            $data = db('goods')->where("cat_id='{$cat_id}' and goods_type = 3 and name like '%银行%'  ")->paginate(1000,true,[
            'page' => $page,
        ]);
           
        }
         
       
         echo json_encode($data);
    }

    // 获得商品详情
    public function goodsDetail(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $goos_id = $arr["goods_id"];

        $data = db('goods')->where('id',$goos_id)->select();

       echo json_encode($data);

    }

    // 收藏商品
    public function goodsLove(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $open_id = $arr["open_id"];
        $goods_id = $arr["goods_id"];
        // 操作情况 0表示查询 1表示插入数据 2表示删除数据 
        $control = $arr["control"];

        switch ($control) {
            // 0 表示查询
            case '0':
            $data = db('collects')->where("user_id = '{$open_id}' and goods_id = '{$goods_id}'")->select();

         
                if($data){
                    echo 1;
                }else {
                    echo 0;
                }
                
                break;
            // 1 1表示插入数据
            case '1':
                $data = [
                    'user_id'=> $open_id,
                    'goods_id' => $goods_id,
                    'times' => time()
                ];
                $result = db('collects')->insert($data);

                if($result){
                    echo 1;
                }else {
                    echo 0;
                }
                break;
            // 2 2表示删除数据 
            case '2':
            // 分页测试数据 , 每次传一条数据,以后再修改
            $data = db('collects')->where("user_id = '{$open_id}' and goods_id = '{$goods_id}'")->delete();

         
                if($data){
                    echo 1;
                }else {
                    echo 0;
                }
            break;
            
        }
        
    }

    // 获取公司信息
    public function companyInfo(){
        $data = db('about')->find();
        echo json_encode($data);
    }

    // 活动信息
    public function activity(){
        $return = db('articles')-> where('cat_id','5') -> order('sold_out,end_time desc ')-> select();
        //$return = db('articles')-> where("id >65 ") -> order('sold_out,end_time desc ')-> select();
            //判断日期是否过期
           
        foreach ($return as $key => $value) {
                $time =strtotime($value['end_time']);
                if($value['sold_out'] == 1){
                if($time <= time()){
                    $return[$key]['sold_out'] = 2;
                     $id = db('articles')-> where("id = {$value['id']}") ->update(['sold_out' => 2]);
                }
                }
        }
        if($return){
         return json($return);
        }
    }

    // 收藏页面
    public function collection(){

        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $user_id = $arr["user_id"];

        $data = db('collects')->alias('c')
        ->join('goods g','c.goods_id = g.id','left')
        ->where("c.user_id='{$user_id}'")
        ->select();

        
        foreach ($data as $k => $v) {
            $data[$k]["time"] = date('Y-m-d H:i:s',$data[$k]["times"]);
        }

        echo json_encode($data);
    }

    // 详情页面
        // 多页面共用
    public function detailPages(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $id = $arr["id"];

        $data = db('articles')->where('id',$id)->find();
       echo json_encode($data);
    }

    // 品牌街铺 轮播图
    public function bannerBrand(){
        $banner = db('ad')->where('type','2') ->order('pid')-> select();
        echo json_encode($banner);
    }

    // 品牌街铺 合作公司
    public function brandPartner(){
        $data = db('articles')->where('cat_id',6)->select();
        echo json_encode($data); 
    }

    // 团队信息
    public function teamInfo(){
        $data = db('team')->select();
        echo json_encode($data); 
    }

    // 加盟我们 , 接受信息
    // public function joinUs(){
    //     $json = file_get_contents('php://input');
    //     $arr = json_decode($json, TRUE);

    //     $data = db('message')->
    // }

    // joinBanner 加盟我们banner
    public function joinBanner(){
        $data = db('ad')->where('id',15)->find();
        echo json_encode($data); 
    }

    // 登录操作
    public function doLogin()
    {   
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);

        $userName = $arr["user_name"];
        $password = $arr["password"];

        $hasUser = db('user')->where('user_name', $userName)->find();
        if(empty($hasUser)){

            $resutl = array(
                "msg"=>'-3',
            );
            echo json_encode($resutl);
            return ;
        }

        if(md5($password) != $hasUser['password']){
            $resutl = array(
                "msg"=>'-4',
            );
            echo json_encode($resutl);
            return ;
        }

        if(1 != $hasUser['status']){
            $resutl = array(
                "msg"=>'-5',
            );
            echo json_encode($resutl);
            return ;
        }

        
        // $info = $result;

        session('username', $userName);
        session('id', $hasUser['id']);

        // 更新管理员状态
        $param = [
            'login_times' => $hasUser['login_times'] + 1,
            'last_login_ip' => request()->ip(),
            'last_login_time' => time()
        ];
        //$res = $userModel->updateStatus($param, $hasUser['id']);
        db('user')->where('id', $hasUser['id'])->update($param);

        $resutl = array(
            "msg"=>'1',
            "user_id"=>$hasUser['id']
        );

        echo json_encode($resutl);
    }
    // team 信息 
    public function userinfo(){
        $json = file_get_contents('php://input');
        if ($json=='') {
            return "no data";
        }
        $arr = json_decode($json, TRUE);

        $id = $arr["userId"];

        $result = db('user')->alias('u')->join('role r','r.id = u.role_id','left')->field(array('u.id','u.user_name','u.real_name','u.status','u.role_id','u.phone','u.scannum','u.subnum','r.role_name'))->where('u.id', $id)->find();

        $result['subnum'] = db('order')->field('id')->where("salemanid={$id} and state =0")->count();
        db('user')->where('id',$id)->update(['subnum'=>$result['subnum']]);
        $result['fastnum'] = db('rapidorder')->field('id')->where("salemanid={$id} and state =0")->count();
        //$result['num'] = db('user')->where('upid', $id)->count();
        echo json_encode($result);
    }
    // 下级 信息 
    public function lowerUserInfo(){
        $json = file_get_contents('php://input');
        if ($json=='') {
            return "no data";
        }
        //$json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        
        $id = $arr["userId"];

        $result = db('order')->field(array('userName','mobile','sex','id','time','salemanid'))->where('salemanid', $id)->order('id desc')->select();
        foreach($result as $key=>$vo){
                    //读取订单表，每个业务员订单数，更新到用户表的提交表量
                    if($result[$key]['sex']==1){$result[$key]['sex']="男";}else if($result[$key]['sex']==2){$result[$key]['sex']="女";}else if($result[$key]['sex']==''){$result[$key]['sex']="未填写";}
                    $result[$key]['time'] = substr($result[$key]['time'],2,8);
                }
        /*$result = db('user')->field(array('user_name','id','scannum','subnum'))->where('upid', $id)->order('scannum desc')->select();*/
        
        echo json_encode($result);
    }
        // 下级 信息1 
    public function lowerUserInfo1(){
        $json = file_get_contents('php://input');
        if ($json=='') {
            return "no data";
        }
        $arr = json_decode($json, TRUE);

        $id = $arr["userId"];
  
        $result = db('rapidorder')->field(array('fastName','fastPhone','ids','time','salemanid'))->where('salemanid', $id)->order('ids desc')->select();
        foreach($result as $key=>$vo){
                    //读取订单表，每个业务员订单数，更新到用户表的提交表量
                    
                    $result[$key]['time'] = substr($result[$key]['time'],2,8);
                }
        echo json_encode($result);
    }

    // 保存用户详细信息
    public function wxUser(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $openId = $arr["openid"];
        $arr['addtime'] = time();
        if(@$arr['upid'] ==null){
            unset($arr['upid']);
        }
        // 先查询下数据库是否存在该用户
        $find = db('wxuser')->where('openid',$openId)->find();

        if($find){
            $result = db('wxuser')->where('openid',$openId)->update($arr);
            if($result){
               
                //echo $find['upid'];
                echo 1;
               
            }
        }else {
            $result = db('wxuser')->insert($arr);
            if($result){
                echo 1;
                //echo $arr['upid'];
            }
        }
    }
    //保存快速测试
    public function speedinessOrder(){
       $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $order = db('rapidorder');
       
        $sn = date('Ymdhis') . str_pad(mt_rand(1, 9999), 4, '0', STR_PAD_LEFT);

        $d = date("Y-m-d H:i",time());
        //先插入订单的第一和第五页
       
           
        $orderarr  = array(
            'order_sn' => $sn, 
            'time' => $d, 
            'openId' =>isset($arr['openId'])?$arr['openId']:'',
            'fastName' => $arr['fastName'], 
            'fastPhone' => isset($arr['fastPhone'])?$arr['fastPhone']:'',
            'fastAge' => isset($arr['fastAge'])?$arr['fastAge']:'',
            'fastJob' => isset($arr['fastJob'])?$arr['fastJob']:'',
            'fastWorkPlace' => isset($arr['fastWorkPlace'])?$arr['fastWorkPlace'][0]." " .$arr['fastWorkPlace'][1]." ". $arr['fastWorkPlace'][2]:'',
            'fastWorkPlaceDetail' => isset($arr['fastWorkPlaceDetail'])?$arr['fastWorkPlaceDetail']:'',
            'isHouse' => isset($arr['isHouse'])?$arr['isHouse']:'',
            
            'payHouse' => isset($arr['payHouse'])?$arr['payHouse']:'',
            'isInsurance' =>  isset($arr['isInsurance'])?$arr['isInsurance']:'',
            'payInsurance' => isset($arr['payInsurance'])?$arr['payInsurance']:'',
            
            'isCar' => isset($arr['isCar'])?$arr['isCar']:'',
            'payCar' => isset($arr['payCar'])?$arr['payCar']:'',
            'isFund' => isset($arr['isFund'])?$arr['isFund']:'',
           
            'payFund' => isset($arr['payFund'])?$arr['payFund']:'',
            'fastTotalCredit' => isset($arr['fastTotalCredit'])?$arr['fastTotalCredit']:'',
            'fastUsedCredit' =>isset($arr['fastUsedCredit'])?$arr['fastUsedCredit']:'',
            'fastALLCreditBond' => isset($arr['fastALLCreditBond'])?$arr['fastALLCreditBond']:'',
            'salemanid' => isset($arr['SalesmanID'])?$arr['SalesmanID']:'',
            'fastUsedALLCreditBond' => isset($arr['fastUsedALLCreditBond'])?$arr['fastUsedALLCreditBond']:''
           
    );

          $id = $order -> insert($orderarr);
            if($id){
               echo "1"; 
            }
         
        }

    // 全部订单
    public function orderList(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $db = db('order');
        $id = $arr['openId'];

        // “state" 0为默认，1是后台删除，2是小程序前端删除
        $result = $db->where("openId = '{$id}' and state = '0'")->select();


        echo json_encode($result);
    }

    public function completeOrder(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $db = db('order');
        $id = $arr['openId'];

        // 未完成
            // 设完成的订单状态码: x
        $status = '4';

        $result = $db->where("openId = '{$id}' and order_status = '{$status}'")->select();

        // dump($result);die();

        echo json_encode($result);
    }
    // 订单详情
    public function orderDetail(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $db = db('order');
        $openId = $arr['openId'];
        $orderId = $arr['orderId'];

        $data = $db -> where("openId = '{$openId}' and order_sn = '{$orderId}' and state = 0")->find();

        echo json_encode($data);
    }
    // 删除已完成订单
    public function deleteOrder(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $db = db('order');
        $openId = $arr['openId'];
        $orderId = $arr['orderId'];

        $data = $db -> where("openId = '{$openId}' and order_sn = '{$orderId}'")->delete();

        if($data){
            echo 1;
        }else {
            echo 0;
        }
    }
    public function review(){
        $char = db('about')->where('id',2)->find();
        $return=explode("^",$char['content']);
        // var_dump($return);
        echo json_encode($return);
    }
    public function checkOrder(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        //$arr['openId']='ok-z54p4oIgtstl_is_t-RBxU76s';
        $data = db('order') -> where("openId = '{$arr['openId']}'")->order('time desc')->find();

        if ($data) {
            return 1;//存在数据
        }

    }
    public function checkOrders(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        //var_dump($arr);die;
        if (@$arr['code']==1) {
            $db = db('order');
            $data = $db -> where("openId = '{$arr['openId']}'")->order('id desc')->find();
            unset($data['id']);

            $id = $db->insertGetId($data);

            $sn = date('Ymdhis') . str_pad(mt_rand(1, 9999), 4, '0', STR_PAD_LEFT);
            $d = date("Y-m-d H:i",time());

            $arr['order_sn']  = $sn;
            $arr['time']  = $d;
            $arr['aptitude']  = 0;
            $arr['state']  = 0;
            $arr['order_status']  = 0;
            //var_dump($arr);die;
            $re = $db->where("id='{$id}'")->update($arr);
            if ($re) {
                        $list = $db ->where("id = '{$id}' ")-> find();
                        $mobile = $list['mobile'];
                        $code = mt_rand(1000, 9999);
                        $result = sendMsg3($mobile,$code);// 通知反馈
                         $salemanid = $list['salemanid'];
                    if($salemanid != null){
                         $lists = db('user') ->where('id', $salemanid)-> find();
                         $code =  $list['userName'];
                         $mobile = $lists['phone'];
                         $result = sendMsg2($mobile, $code);//业务通知
                     }
                       //后台管理员通知
                        // $code =  "";
                        // $mobile = 18029339183;
                        //  $result = sendMsg4($mobile, $code);
                        //   $mobile = 13925435420;
                        //  $result = sendMsg4($mobile, $code);
                return 1;//更新成功

            }else{
                return 0;
            }
            
        }
}
    //微信小程序获取下线二维码
    public function getQcCode(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        //$arr['id']=20;
        $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
        $path ="/upload/lower/".$arr['id'].'.jpg';
        $link = $http_type.$_SERVER['HTTP_HOST'] . $path;
        //$a=file_get_contents($link);
        //var_dump($a);die;
        /*if ($a) {
            return json_encode($link);
        }*/
        $user = new UserModel();
        $token = $user->getToken();
        ob_end_clean();
        $data_string  = array( 'scene' => $arr['id'],'page' => "pages/index/index");
        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=$token";

        $result = $user->curl_post($url,$data_string);
        
        file_put_contents(ROOT_PATH . 'public' . DS .$path,$result);

        
        
        echo json_encode($link);
    }
    public function sanInser(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        //$arr['id']=20;
        $user = db('user');
        $data = $user->where('id',$arr['id'])->find();
        $this ->statementSum($arr['id'],1);
        $data['scannum'] = $data['scannum']+1;//var_dump($data);die;
        $user->update($data, ['id' => $data['id']]);


    }
    public function loan(){

        $arr = '欠款';//贷款
        return json( $arr);
    }
    public function loans(){
        
        $arr = '借';//贷
        return json( $arr);
    }
    public function imgapi(){
        //$arr = 'https://mp.csnet.net.cn/static/admin/images/fastTest.jpg';
         $arr = 'https://mp.csnet.net.cn/static/admin/images/ssssss.png';
        return json($arr);
    }
    public function statementSum($id,$number,$y=null){
        $arr['year'] = date('Y');
        $arr['month'] = date('m');
        $arr['uid'] = $id;

        $statement = db('statement');
        $info = $statement ->where("year = '{$arr['year']}' and month = '{$arr['month']}' and  uid = '{$id}' ") ->find();
         $statementList = $statement ->where(" uid = '{$id}' ") ->select();
        if($info == null and $number == 1){
            $arr['scannum'] =1;
             $statement ->insert($arr);
        }else{
            
            if($number ==1){
            
                $statement ->where("id = '{$info['id']}'")->update(['scannum' => $info['scannum']+1]);
             }elseif($number ==2){
                 $arr = db('order') ->where('salemanid',$id) ->select();
                 foreach ($statementList as $key => $values) {
                    $i = 0;
                    foreach ($arr as $key => $value) {
                         $year = date("Y",strtotime($value['time']));
                         $month = date("m",strtotime($value['time']));
                         if($year == $values['year'] and $month == $values['month']){
                            $i =$i+1;
                        }
                    
                      $statement ->where("id = '{$info['id']}'")->update(['subnum' => $i]);
                    }
                }   

                    if($y != null){
                         
                        
                        $statementLists = $statement ->where(" uid = '{$id}' and year = '{$y}'") ->select();
                        if($statementLists == null){
                            echo 1;
                        }else{

                            foreach ($statementLists as $key => $value) {
                               $statementLists[$key]['date'] = $value['year']."-".$value['month'];
                            }
                        return json($statementLists);
                            }
                }
             }

         }

    }
    //获取业务员名称 用于打电话
    public function getUserName(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $name = db('user') -> where('id',$arr['id']) ->find();
        echo json_encode($name['real_name']);
    }
    //接收加盟信息
    public function insertJoin(){
        $json = file_get_contents('php://input');
        $arr = json_decode($json, TRUE);
        $date  = array('name' => $arr['name'], 
                        'phone' => $arr['phone'],
                        'item' => $arr['job'],
                        'message' => $arr['content'],
                        'time' =>date("Y-m-d H:i:s",time())
                           
        );

        $id = db('joinus') -> insert($date);
        echo 1;
    }

     public function sendSms()
        {
            $json = file_get_contents('php://input');
            $arr = json_decode($json, TRUE);

            $mobile = $arr['mobile'];
            
            
            $code = mt_rand(1000, 9999);
            $result = sendMsg($mobile, $code);
            //$result['Code'] = 'OK';
            if ($result['Code'] == 'OK') {
                // //存到缓存当中,并且返回json数据给前端
                // cache('tel' . $mobile, $code, 39);
                return $code;
            }else{
                return 'test';
            }
        }







}